<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@include file="/context/mytags.jsp"%>
<div class="portlet box green">
	<div class="portlet-title">
		<div class="caption">
			<i class="fa fa-gift"></i>
			<c:if test="${subarea != null }">分区编辑</c:if>
			<c:if test="${subarea == null }">分区添加</c:if>
		</div>
  </div>
  <div class="portlet-body form">
  	<form id="subareaForm" class="form-horizontal form-bordered" action="/user/save" method="post" enctype="multipart/form-data">
  		
  		<div class="form-group">
        <label class="col-md-3 control-label">选择区域:</label>
        <div class="col-md-4">
        	<div class="input-icon right">
	        	<i class="fa"></i>
	          		<select name="regionId" class="form-control select2" style="padding: 0;" required>
		           </select>
	        </div>
        </div>
      </div>
      
  		<div class="form-group">
        <label class="col-md-3 control-label">关键字:</label>
        <div class="col-md-4">
        	<div class="input-icon right">
	        	<i class="fa"></i>
	          <input type="text" class="form-control" name="addresskey" value="${subarea.addresskey}" required maxlength="50"/>
	        </div>
        </div>
      </div>
      
  		<div class="form-group">
        <label class="col-md-3 control-label">起始号:</label>
        <div class="col-md-4">
        	<div class="input-icon right">
	        	<i class="fa"></i>
	          <input type="text" class="form-control" name="startnum" value="${subarea.startnum}" required maxlength="50"/>
	        </div>
        </div>
      </div>
      
  		<div class="form-group">
        <label class="col-md-3 control-label">终止号:</label>
        <div class="col-md-4">
        	<div class="input-icon right">
	        	<i class="fa"></i>
	          <input type="text" class="form-control" name="endnum" value="${subarea.endnum}" required maxlength="50"/>
	        </div>
        </div>
      </div>
      
  		<div class="form-group">
        <label class="col-md-3 control-label">单双号:</label>
        <div class="col-md-4">
        	<div class="input-icon right">
	        	<i class="fa"></i>
		         <select name="single" class="form-control select2" style="padding: 0;" required>
		          		<option value="0">单双号</option>  
					    <option value="1">单号</option>  
					    <option value="2">双号</option>  
		          </select>
	        </div>
        </div>
      </div>
      
  		<div class="form-group">
        <label class="col-md-3 control-label">位置信息:</label>
        <div class="col-md-4">
        	<div class="input-icon right">
	        	<i class="fa"></i>
	          <input type="text" class="form-control" name="position" value="${subarea.position}" required maxlength="50"/>
	        </div>
        </div>
      </div>
      
       <div class="form-actions">
        <div class="col-md-9 col-md-offset-3">
          <button type="button" class="btn btn-primary" onclick="saveSubarea(this)">
          	<spring:message code="btn.save"></spring:message>
          </button>
          <button type="reset" class="btn btn-default" onclick="cancel()">
          	<spring:message code="btn.return"></spring:message>
          </button>
        </div>
      </div>
      <input type="hidden" name="id" value="${subarea.id}">
  	</form>
  </div>
</div>
<script type="text/javascript" src="<c:url value="/static/custom/datepicker-util.js"></c:url>"></script>
<script type="text/javascript">

	$(function(){
		var url = "${webRoot}/region/findAll";
		$.post(url, {}, function(result){
			if(result.code == 0) {
				$.each(result.data, function(index, item){
					$("select[name='regionId']").append("<option value='"+ item.id +"'>" + item.name +"</option>");
				})
			}else {
				layer.msg(result.message, {shift: 6});
			}
		})
	})
	
	function saveSubarea(obj){
		if($('#subareaForm').valid()){
			
			var formData = new FormData($('#subareaForm')[0]);
			$.ajax({
				type: 'post',
				url: '<c:url value="/subarea/save"></c:url>',
				data: formData,
				async: false,  
			    cache: false,  
			    contentType: false,  
			    processData: false, 
				dataType: 'json',
				success: function(data){
					if(data.code == 0) {
						layer.msg(data.message, {shift: 1});
						setTimeout(function(){
							search();
							$(".panel-search").show();
						}, 1200);
					}else {
						layer.msg(data.message, {shift: 6});
					}
				}
			});
		}
	}
</script>